function Xajax(){this.workId='xajaxWork'+new Date().getTime();this.depth=0;this.getRequestObject=function(){var req;try{req=new ActiveXObject("Msxml2.XMLHTTP");} catch(e){try{req=new ActiveXObject("Microsoft.XMLHTTP");} catch(e2){req=null;} } if(!req&&typeof XMLHttpRequest!="undefined") req=new XMLHttpRequest();return req;} this.$=function(sId){return document.getElementById(sId);} this.getFormValues=function(frm){var objForm;if(typeof(frm)=="string") objForm=this.$(frm);else objForm=frm;var sXml="";if(objForm&&objForm.tagName=='FORM'){var formElements=objForm.elements;for(var i=0;i < formElements.length;i++){if((formElements[i].type=='radio'||formElements[i].type=='checkbox')&&formElements[i].checked==false) continue;var name=formElements[i].name;if(name){if(sXml!='') sXml+='&';sXml+=name+"="+encodeURIComponent(formElements[i].value);} } } sXml+="";return sXml;} this.getPostFormValues=function(frm){var objForm;if(typeof(frm)=="string") objForm=this.$(frm);else objForm=frm;var datafields=new Array();var check_dataarray=new Array();var select_dataarray=new Array();var uri=xajaxRequestUri;for(var i=0;i < objForm.elements.length;++i){if(val_name=objForm.elements[i].name){switch(objForm.elements[i].type){case 'checkbox':{if(check_dataarray.length==0){namestring=new String(objForm.elements[i].id);first_pos=0;last_pos=namestring.length;val_checkname=namestring.substring(first_pos,last_pos-1);} if(objForm.elements[i].checked==true){check_dataarray.push(objForm.elements[i].value);} datafields[val_checkname]=check_dataarray;}break;case 'radio':{radioObject=objForm.elements[i];val_radioname=objForm.elements[i].name;if(radioObject.checked==true){datafields[val_radioname]=radioObject.value;} }break;case 'select-one':{datafields[val_name]=objForm.elements[i].value;}break;case 'select-multiple':{listObject=objForm.elements[i].name;for(var j=0;j < objForm.elements[i].length;j++){alert(listObject.options[j].value);if(listObject.options[j].selected==true){select_dataarray.push(listObject.options[j].value);} } if(select_dataarray.length==1){datafields[radioObject]=select_dataarray[0];}else{datafields[radioObject]=select_dataarray;} }break;case 'file': case 'button': case 'reset': case 'submit':{}break;default:{datafields[val_name]=objForm.elements[i].value;break;} } } } return datafields;} this.objectToXML=function(obj){var sXml="";for(i in obj){try{if(i=='constructor') continue;if(obj[i]&&typeof(obj[i])=='function') continue;var key=i;var value=obj[i];if(value&&typeof(value)=="object"&& (value.constructor==Array )&&this.depth <=50){this.depth++;value=this.objectToXML(value);this.depth--;} sXml+=""+key+""+value+"";} catch(e){} } sXml+="";return sXml;} this.call=function(sFunction,aArgs,sRequestType){var i,r,postData;if(document.body) document.body.style.cursor='wait';var xajaxRequestType=sRequestType;var uri=xajaxRequestUri;var value;switch(xajaxRequestType){case 0:{var uriGet=uri.indexOf("?")==-1?"?xajax="+encodeURIComponent(sFunction):"&xajax="+encodeURIComponent(sFunction);for(i=0;i < aArgs.length;i++){value=aArgs[i];if(typeof(value)=="object") value=this.objectToXML(value);uriGet+="&xajaxargs[]="+encodeURIComponent(value);} uriGet+="&xajaxr="+new Date().getTime();uri+=uriGet;postData=null;}break;case 1:{postData="xajax="+encodeURIComponent(sFunction);postData+="&xajaxr="+new Date().getTime();for(i=0;i < aArgs.length;i++){value=aArgs[i];if(typeof(value)=="object") value=this.objectToXML(value);postData=postData+"&xajaxargs[]="+encodeURIComponent(value);} }break;default: alert("Illegal request type: "+xajaxRequestType);return false;break;} r=this.getRequestObject();r.open(xajaxRequestType==0?"GET":"POST",uri,true);if(xajaxRequestType==1){try{r.setRequestHeader("Method","POST "+uri+" HTTP/1.1");r.setRequestHeader("Content-Type","application/x-www-form-urlencoded");} catch(e){alert("Your browser does not appear to support asynchronous requests using POST.");return false;} } r.onreadystatechange=function(){if(r.readyState!=4) return;if(r.status==200){var data=r.responseXML;if(data) xajax.processResponse(data);} } r.send(postData);delete r;return true;} this.willChange=function(element,attribute,newData){var oldData;if(attribute=="innerHTML"){tmpXajax=this.$(this.workId);if(tmpXajax==null){tmpXajax=document.createElement("div");tmpXajax.setAttribute('id',this.workId);tmpXajax.style.display="none";tmpXajax.style.visibility="hidden";document.body.appendChild(tmpXajax);} tmpXajax.innerHTML=newData;newData=tmpXajax.innerHTML;} eval("oldData=document.getElementById('"+element+"')."+attribute);if(newData!=oldData) return true;return false;} this.processResponse=function(xml){var tmpXajax=null;xml=xml.documentElement;for(i=0;i < xml.childNodes.length;i++){if(xml.childNodes[i].nodeName=="alert"){if(xml.childNodes[i].firstChild) alert(xml.childNodes[i].firstChild.nodeValue);} if(xml.childNodes[i].nodeName=="jscript"){if(xml.childNodes[i].firstChild) eval(xml.childNodes[i].firstChild.nodeValue);} if(xml.childNodes[i].nodeName=="update"){var action;var element;var attribute;var search;var data;var type;var objElement;for(j=0;j < xml.childNodes[i].attributes.length;j++){if(xml.childNodes[i].attributes[j].name=="action"){action=xml.childNodes[i].attributes[j].value;} } var node=xml.childNodes[i];for(j=0;j < node.childNodes.length;j++){if(node.childNodes[j].nodeName=="target"){for(k=0;k < node.childNodes[j].attributes.length;k++){if(node.childNodes[j].attributes[k].name=="attribute"){attribute=node.childNodes[j].attributes[k].value;} } element=node.childNodes[j].firstChild.nodeValue;} if(node.childNodes[j].nodeName=="search"){if(node.childNodes[j].firstChild) search=node.childNodes[j].firstChild.nodeValue;else search="";} if(node.childNodes[j].nodeName=="data"){if(node.childNodes[j].firstChild) data=node.childNodes[j].firstChild.nodeValue;else data="";} if(node.childNodes[j].nodeName=="type"){if(node.childNodes[j].firstChild) type=node.childNodes[j].firstChild.nodeValue;else type="";} } if(action=="assign"){if(this.willChange(element,attribute,data)){eval("document.getElementById('"+element+"')."+attribute+"=data;");} } if(action=="append") eval("document.getElementById('"+element+"')."+attribute+"+=data;");if(action=="prepend") eval("document.getElementById('"+element+"')."+attribute+"=data+document.getElementById('"+element+"')."+attribute);if(action=="replace"){eval("var v=document.getElementById('"+element+"')."+attribute);var v2=v.indexOf(search)==-1?v:"";while(v.indexOf(search)>-1){x=v.indexOf(search)+search.length+1;v2+=v.substr(0,x).replace(search,data);v=v.substr(x,v.length-x);} if(this.willChange(element,attribute,v2)) eval('document.getElementById("'+element+'").'+attribute+'=v2;');} if(action=="clear") eval("document.getElementById('"+element+"')."+attribute+"='';");if(action=="remove"){objElement=this.$(element);if(objElement.parentNode&&objElement.parentNode.removeChild){objElement.parentNode.removeChild(objElement);} } if(action=="create"){var objParent=this.$(element);objElement=document.createElement(attribute);objElement.setAttribute('id',data);if(type&&type!='') objElement.setAttribute('type',type);objParent.appendChild(objElement);if(objParent.tagName=="FORM"){} } } } document.body.style.cursor='default';} } var xajax=new Xajax();function xajax_doForm(){xajax.call("doForm",arguments,1);}